package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.system.domain.LanguageType;
import com.ruoyi.system.domain.SysMenuLanguage;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.mapper.SysMenuLanguageMapper;
import com.ruoyi.system.service.ILanguageTypeService;
import com.ruoyi.system.service.ISysMenuLanguageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Locale;

/**
 * 菜单语言Service业务层处理
 *
 * @author ruoyi
 * @date 2022-04-26
 */
@Service
public class SysMenuLanguageServiceImpl implements ISysMenuLanguageService {
    @Autowired
    private SysMenuLanguageMapper menuLanguageMapper;
    @Autowired
    private ILanguageTypeService languageTypeService;

    /**
     * 查询菜单语言
     *
     * @param id 菜单语言主键
     * @return 菜单语言
     */
    @Override
    public SysMenuLanguage selectSysMenuLanguageById(Long id) {
        return menuLanguageMapper.selectSysMenuLanguageById(id);
    }

    /**
     * 查询菜单语言列表
     *
     * @param sysMenuLanguage 菜单语言
     * @return 菜单语言
     */
    @Override
    public Page<SysMenuLanguage> selectSysMenuLanguageList(Page<SysMenuLanguage> page, SysMenuLanguage sysMenuLanguage) {
        Page<SysMenuLanguage> sysMenuLanguages = menuLanguageMapper.selectSysMenuLanguageList(page,sysMenuLanguage);
        return sysMenuLanguages;
    }

    /**
     * 新增菜单语言
     *
     * @param sysMenuLanguage 菜单语言
     * @return 结果
     */
    @Override
    public int insertSysMenuLanguage(SysMenuLanguage sysMenuLanguage) {
        return menuLanguageMapper.insertSysMenuLanguage(sysMenuLanguage);
    }

    /**
     * 修改菜单语言
     *
     * @param sysMenuLanguage 菜单语言
     * @return 结果
     */
    @Override
    public int updateSysMenuLanguage(SysMenuLanguage sysMenuLanguage) {
        return menuLanguageMapper.updateSysMenuLanguage(sysMenuLanguage);
    }


    /**
     * 删除菜单语言信息
     *
     * @param id 菜单语言主键
     * @return 结果
     */
    @Override
    public int deleteSysMenuLanguageById(Long id) {
        return menuLanguageMapper.deleteSysMenuLanguageById(id);
    }

    @Override
    public List<SysMenuLanguage> selectMenusByMenuAndLanguage(List<Long> menuCodes) {
        Locale locale = LocaleContextHolder.getLocale();
        return menuLanguageMapper.selectMenusByMenuAndLanguage(menuCodes, locale.getLanguage());
    }
}